<?php

namespace app\api\controller;
use app\common\service\lib\BaiduApi;
use app\common\service\lib\Tuling;
class Talk extends  Base
{
    /**
     * Author:William
     * @return mixed
     */
    public function index()
    {
        $text = request()->get('text');
        $id = request()->get('id');
        $id = 1;
        //敏感词实例
        $baidu = new BaiduApi();
        $baiduRes = $baidu->index($text);
        if ($baiduRes['conclusionType'] == 2) {
            return $this->result($baiduRes['conclusion'],'400');
        }
        //图灵机器人实例
        $tuling = new Tuling();
        $tulingRes = $tuling->index($text, $id);
        return $this->result($tulingRes,'200');
    }


    public function baiduTalk()
    {
        $text = request()->get('text');
        //敏感词实例
        $baidu = new BaiduApi();
        $baiduRes = $baidu->index($text);
        isset( $baiduRes['conclusionType'])?$baiduRes['conclusionType']:$baiduRes['conclusionType'];
        if ($baiduRes['conclusionType'] == 2) {
            return json(['code' => 400, 'msg' => '你的发言' . $baiduRes['conclusion'], 'data' => '']);
        }
        return json(['code' => 200, 'msg' => '你的发言' . $baiduRes['conclusion'], 'data' => $baiduRes]);
    }
}